package com.leilei.model;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created by yvdedu.com on 2016/11/17.
 */
public class SafePlace {
    private Point point;
    private AtomicInteger health=new AtomicInteger(50);

    public SafePlace() {
        this.point=new Point(1000,1000);
    }

    public SafePlace(Point point, AtomicInteger health) {

        this.point = point;
        this.health = health;
    }

    public Point getPoint() {
        return point;
    }

    public void setPoint(Point point) {
        this.point = point;
    }

    public AtomicInteger getHealth() {
        return health;
    }

    public void setHealth(AtomicInteger health) {
        this.health = health;
    }

    public boolean dropHealth(){
        if (this.health.get()>0){
            int i = this.health.decrementAndGet();
            if(i<=0){
                new Thread(()->{
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    this.health.set(50);
                    this.point=new Point(1000,1000);
                }).start();
            }
            return true;
        }
        return false;
    }
}
